Transmission Control Protocol (TCP) is a data communications protocol and provides a reliable stream of data between two connected computers.
TCP is the base protocol for Telnet, FTP, SMTP, HTTP, POP, IMAP and other upper-layer protocols that use stream-based communications. In other words, any of these more complicated protocols can be implemented using TCP. In fact, PowerTCP does exactly this, as it uses the Tcp component's base classes for all TCP-related communications.
Features
TCP is built upon IP (Internet Protocol), which provides an unreliable transfer of data. In order to provide a reliable data stream, TCP uses the following methods:
- When one end of a connection receives data, it sends an acknowledgement message. The sender continues to send the data until it receives this acknowledgement or times out.
- Checksums are used to ensure no data corruption occurs. If data received does not match data sent, the host discards the data and does not acknowledge.
- Both ends use buffering to store data before it is used by the application, and ensures the buffer will not overflow. This is known as flow control.
- Data may be split up or combined into segments of any size. Bytes sent from one end of a connection arrive at the other end in the same order, but not necessarily in identically sized segments.
- TCP is built upon the unreliable IP and therefore may change the order of received data and delete duplicate data to ensure reliability.
- TCP is a stream-oriented protocol; data flows without predictable breaks. It is up to the application to define meaningful record blocks.
- TCP provides simultaneous two-way (full-duplex) data transfer. Data can flow both ways simultaneously, although most protocols use half-duplex communication (each side stops while the other sends) to maintain sequential operation.
Connections
TCP is a connection-oriented protocol, meaning a connection is established between two hosts before data is exchanged:
- A client sends a message to a server requesting a connection. The server has a Daemon process running on a port that handles this request.
- The server responds, acknowledging the connect request.
- The client in turn acknowledges the server's message.
The server must listen for connections before the client can connect. The following two actions occurred:
- The server made a passive connection—it listened for clients trying to connect.
- The client made an active connection.
While the connection is active, it is uniquely defined by four TCP packet values:
- Two port numbers that identify the source and destination TCP port. Port numbers are used by the operating system to route the data to the application "bound" to that port.
- Two 4-byte addresses that identify the source and destination host interface. For example, a notebook computer may have one IP address for a LAN card and one IP address for RAS connections using COM3. This would be considered a "multi-homed host," and applications can bind to either port.
Closing a connection works similarly to establishing a connection. One end makes an active close and the other end performs a passive close.
See Also